/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model.utility;

import model.game.GameInterface;
import model.map.GridMap;
import model.map.cell.Cell;
import model.map.cell.NonPlantableCell;
import model.map.cell.PlantableCell;

/**
 *
 * @author dolphinigle
 */
public class MapUtility {

  /**
   * Retrieves any plantable cell from a map
   * for testing
   */
  public static PlantableCell getPlantableCell(GridMap map) {
    for (int i = 0; i < map.getRow(); ++i) {
      for (int j = 0; j < map.getColumn(); ++j) {
        if (map.getCellAt(j, i).isPlantable()) {
          return (PlantableCell)map.getCellAt(j,i);
        }
      }
    }
    assert false; // not found
    return null;
  }

  /**
   * Retrieves any nonplantable cell from a map
   * for testing
   */
  public static NonPlantableCell getNonPlantableCell(GridMap map) {
    for (int i = 0; i < map.getRow(); ++i) {
      for (int j = 0; j < map.getColumn(); ++j) {
        if (!map.getCellAt(j, i).isPlantable() &&
                map.getCellAt(j,i).isEnterable()) {
          return (NonPlantableCell)map.getCellAt(j,i);
        }
      }
    }
    assert false; // not found
    return null;
  }

  /**
   * Retrieves any enterable cell from a map
   * for testing
   */
  public static Cell getEnterableCell(GridMap map) {
    for (int i = 0; i < map.getRow(); ++i) {
      for (int j = 0; j < map.getColumn(); ++j) {
        if (map.getCellAt(j,i).isEnterable()) {
          return map.getCellAt(j,i);
        }
      }
    }
    assert false; // not found
    return null;
  }

  /**
   * Retrieves any cell containing crystal a game
   * for testing
   */
  public static Cell getCellContainingCrystal(GameInterface game) {
    GridMap map = game.getMaps().getField();
    for (int i = 0; i < map.getRow(); ++i) {
      for (int j = 0; j < map.getColumn(); ++j) {
        Cell c = map.getCellAt(j,i);
        if (game.getCreatures().getCrystals().containsCrystalAt(c)) {
          return c;
        }
      }
    }
    assert false; // not found
    return null;
  }

  /**
   * Retrieves any cell containing drop box a game
   * for testing
   */
  public static Cell getCellContainingDropBox(GameInterface game) {
    GridMap map = game.getMaps().getField();
    for (int i = 0; i < map.getRow(); ++i) {
      for (int j = 0; j < map.getColumn(); ++j) {
        Cell c = map.getCellAt(j,i);
        if (game.getCreatures().getDropBoxes().containsDropBoxAt(c)) {
          return c;
        }
      }
    }
    assert false; // not found
    return null;
  }

}
